package com.bank.Servlets;


import com.bank.dao.impl.UserDaoImpl;
import com.bank.model.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/loginServlet")
public class LoginServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        //调用底层类进行处理
        UserDaoImpl userDao=new UserDaoImpl();
        User user=userDao.login(username,password);

        HttpSession session = request.getSession();
        session.setAttribute("LoginUser",user);


        if (user==null){
            response.sendRedirect("login.jsp");
        }
        else {
            response.sendRedirect("mainmenu.jsp");
        }
    }
}
